<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script src="spellcheck_test.js"></script>

<script>
spellcheck_test(
    '<span contenteditable id="target"></span>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = true;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<span contenteditable id="target" spellcheck="true">Hello, #zz#.\u00A0</span>',
    'Change "spellcheck" of <span> from undefined to true');

spellcheck_test(
    '<span contenteditable id="target"></span>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = false;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<span contenteditable id="target" spellcheck="false">Hello, zz.\u00A0</span>',
    'Change "spellcheck" of <span> from undefined to false');

spellcheck_test(
    '<span contenteditable id="target" spellcheck="true"></span>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = true;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<span contenteditable id="target" spellcheck="true">Hello, #zz#.\u00A0</span>',
    'Change "spellcheck" of <span> from true to true');

spellcheck_test(
    '<span contenteditable id="target" spellcheck="true"></span>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = false;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<span contenteditable id="target" spellcheck="false">Hello, zz.\u00A0</span>',
    'Change "spellcheck" of <span> from true to false');

spellcheck_test(
    '<span contenteditable id="target" spellcheck="false"></span>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = true;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<span contenteditable id="target" spellcheck="true">Hello, #zz#.\u00A0</span>',
    'Change "spellcheck" of <span> from false to true');

spellcheck_test(
    '<span contenteditable id="target" spellcheck="false"></span>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = false;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<span contenteditable id="target" spellcheck="false">Hello, zz.\u00A0</span>',
    'Change "spellcheck" of <span> from false to false');

spellcheck_test(
    '<input id="target">',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = true;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<input id="target" spellcheck="true" value="Hello, #zz#. ">',
    'Change "spellcheck" of <input> from undefined to true');

spellcheck_test(
    '<input id="target">',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = false;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<input id="target" spellcheck="false" value="Hello, zz. ">',
    'Change "spellcheck" of <input> from undefined to false');

spellcheck_test(
    '<input id="target" spellcheck="true">',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = true;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<input id="target" spellcheck="true" value="Hello, #zz#. ">',
    'Change "spellcheck" of <input> from true to true');

spellcheck_test(
    '<input id="target" spellcheck="true">',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = false;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<input id="target" spellcheck="false" value="Hello, zz. ">',
    'Change "spellcheck" of <input> from true to false');

spellcheck_test(
    '<input id="target" spellcheck="false">',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = true;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<input id="target" spellcheck="true" value="Hello, #zz#. ">',
    'Change "spellcheck" of <input> from false to true');

spellcheck_test(
    '<input id="target" spellcheck="false">',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = false;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<input id="target" spellcheck="false" value="Hello, zz. ">',
    'Change "spellcheck" of <input> from false to false');

spellcheck_test(
    '<textarea id="target"></textarea>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = true;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<textarea id="target" spellcheck="true">Hello, #zz#. </textarea>',
    'Change "spellcheck" of <textarea> from undefined to true');

spellcheck_test(
    '<textarea id="target"></textarea>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = false;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<textarea id="target" spellcheck="false">Hello, zz. </textarea>',
    'Change "spellcheck" of <textarea> from undefined to false');

spellcheck_test(
    '<textarea id="target" spellcheck="true"></textarea>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = true;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<textarea id="target" spellcheck="true">Hello, #zz#. </textarea>',
    'Change "spellcheck" of <textarea> from true to true');

spellcheck_test(
    '<textarea id="target" spellcheck="true"></textarea>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = false;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<textarea id="target" spellcheck="false">Hello, zz. </textarea>',
    'Change "spellcheck" of <textarea> from true to false');

spellcheck_test(
    '<textarea id="target" spellcheck="false"></textarea>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = true;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<textarea id="target" spellcheck="true">Hello, #zz#. </textarea>',
    'Change "spellcheck" of <textarea> from false to true');

spellcheck_test(
    '<textarea id="target" spellcheck="false"></textarea>',
    document => {
      const target = document.getElementById('target');
      target.spellcheck = false;
      target.focus();
      document.execCommand('insertText', false, 'Hello, ');
      document.execCommand('insertText', false, 'zz. ');
    },
    '<textarea id="target" spellcheck="false">Hello, zz. </textarea>',
    'Change "spellcheck" of <textarea> from false to false');
</script>
